package com.xzit.rental;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Collections;

@SpringBootTest
public class GeneratorCode {

    private static final String JDBC_URL = "jdbc:mysql://localhost:3306/auto_rental";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "75315978";
    private static final String AUTHOR = "何时说晚安";
    private static final String OUT_PUT_DIR = ".\\src\\main\\java";
    private static final String PACKAGE_NAME = "com.xzit";
    private static final String MODULE_NAME = "rental";
    private static final String PATH_INFO = ".\\src\\main\\resources\\mapper";
    private static final String[] TABLES = {
            "auto_brand","auto_info","auto_maker","busi_customer",
            "busi_maintain","busi_order","busi_rental_type",
            "busi_violation","sys_dept","sys_permission","sys_role",
            "sys_role_permission","sys_user","sys_user_role"
    };
    private static final String[] TABLE_PREFIXES = {"busi_","sys_"};

    @Test
    public void generator(){
        FastAutoGenerator.create(JDBC_URL,USERNAME,PASSWORD)
                .globalConfig(builder -> {
                    builder.author(AUTHOR) // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir(OUT_PUT_DIR); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent(PACKAGE_NAME) // 设置父包名
                            .moduleName(MODULE_NAME)// 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml,PATH_INFO)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(TABLES) // 设置需要生成的表名
                            .addTablePrefix(TABLE_PREFIXES) // 设置过滤表前缀
                            .entityBuilder().enableLombok() //开启lombok
                            .enableChainModel()//开启链式编程
                            .controllerBuilder().enableRestStyle(); //开启restController
                    //  .logicDeletePropertyName("deleted")
                    // .logicDeleteColumnName("deleted");//配置逻辑删除处理
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}
